﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;/*给 [DllImport("kernel32.dll")] 调用dll 不需要IDE里面引用  用这个*/


using System.IO;//文件保存

namespace CPU卡调试神器FM1208V1._0
{
    public partial class CPU卡调试神器FM1208 : Form
    {

        static int button23_Click_flag=1;
        float xvalues;//MOVE
        float yvalues;//MOVE

        [DllImport("DES.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern void DO_DES(byte[] MesIn, byte[] KeyIn, byte[] MesOut);

        [DllImport("DES.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
        public unsafe static extern void DO_3DES(byte[] MesIn, byte[] KeyIn, byte[] MesOut);

        /// <summary>
        /// ////////////////////上面是自己的DES////////////////////
        /// </summary>
        /// <param name="dwMilliseconds"></param>
        [DllImport("kernel32.dll")]
        static extern void Sleep(int dwMilliseconds);

        //=========================== System Function =============================
        [DllImport("hfrdapi.dll")]
        static extern int Sys_GetDeviceNum(UInt16 vid, UInt16 pid, ref UInt32 pNum);

        [DllImport("hfrdapi.dll")]
        static extern int Sys_GetHidSerialNumberStr(UInt32 deviceIndex,
                                                    UInt16 vid,
                                                    UInt16 pid,
                                                    [Out]StringBuilder deviceString,
                                                    UInt32 deviceStringLength);

        [DllImport("hfrdapi.dll")]
        static extern int Sys_Open(ref IntPtr device,
                                   UInt32 index,
                                   UInt16 vid,
                                   UInt16 pid);

        [DllImport("hfrdapi.dll")]
        static extern bool Sys_IsOpen(IntPtr device);

        [DllImport("hfrdapi.dll")]
        static extern int Sys_Close(ref IntPtr device);

        [DllImport("hfrdapi.dll")]
        static extern int Sys_SetLight(IntPtr device, byte color);

        [DllImport("hfrdapi.dll")]
        static extern int Sys_SetBuzzer(IntPtr device, byte msec);

        [DllImport("hfrdapi.dll")]
        static extern int Sys_SetAntenna(IntPtr device, byte mode);

        [DllImport("hfrdapi.dll")]
        static extern int Sys_InitType(IntPtr device, byte type);

        //=========================== Auxiliary Function ===========================
        [DllImport("hfrdapi.dll")]
        static extern int Aux_SingleDES(byte desType,
                                        byte[] key,
                                        byte[] srcData,
                                        UInt32 srcDataLen,
                                        byte[] destData,
                                        ref UInt32 destDataLen);

        [DllImport("hfrdapi.dll")]
        static extern int Aux_TripleDES(byte desType,
                                        byte[] key,
                                        byte[] srcData,
                                        UInt32 srcDataLen,
                                        byte[] destData,
                                        ref UInt32 destDataLen);

        [DllImport("hfrdapi.dll")]
        static extern int Aux_SingleMAC(byte[] key,
                                        byte[] initData,
                                        byte[] srcData,
                                        UInt32 srcDataLen,
                                        byte[] macData);

        [DllImport("hfrdapi.dll")]
        static extern int Aux_TripleMAC(byte[] key,
                                        byte[] initData,
                                        byte[] srcData,
                                        UInt32 srcDataLen,
                                        byte[] macData);

        //=========================== M1 Card Function =============================
        [DllImport("hfrdapi.dll")]
        static extern int TyA_Request(IntPtr device, byte mode, ref UInt16 pTagType);

        [DllImport("hfrdapi.dll")]
        static extern int TyA_Anticollision(IntPtr device,
                                            byte bcnt,
                                            byte[] pSnr,
                                            ref byte pLen);

        [DllImport("hfrdapi.dll")]
        static extern int TyA_Select(IntPtr device,
                                     byte[] pSnr,
                                     byte snrLen,
                                     ref byte pSak);

        [DllImport("hfrdapi.dll")]
        static extern int TyA_Halt(IntPtr device);

        [DllImport("hfrdapi.dll")]
        static extern int TyA_CS_Authentication2(IntPtr device,
                                                 byte mode,
                                                 byte block,
                                                 byte[] pKey);

        [DllImport("hfrdapi.dll")]
        static extern int TyA_CS_Read(IntPtr device,
                                      byte block,
                                      byte[] pData,
                                      ref byte pLen);

        [DllImport("hfrdapi.dll")]
        static extern int TyA_CS_Write(IntPtr device, byte block, byte[] pData);

        [DllImport("hfrdapi.dll")]
        static extern int TyA_CS_InitValue(IntPtr device, byte block, Int32 value);

        [DllImport("hfrdapi.dll")]
        static extern int TyA_CS_ReadValue(IntPtr device, byte block, ref Int32 pValue);

        [DllImport("hfrdapi.dll")]
        static extern int TyA_CS_Decrement(IntPtr device, byte block, Int32 value);

        [DllImport("hfrdapi.dll")]
        static extern int TyA_CS_Increment(IntPtr device, byte block, Int32 value);

        [DllImport("hfrdapi.dll")]
        static extern int TyA_CS_Restore(IntPtr device, byte block);

        [DllImport("hfrdapi.dll")]
        static extern int TyA_CS_Transfer(IntPtr device, byte block);

        //======================= Ultralight(C) Card Function ========================= 
        [DllImport("hfrdapi.dll")]
        static extern int TyA_UL_Select(IntPtr device, byte[] pSnr, ref byte pLen);

        [DllImport("hfrdapi.dll")]
        static extern int TyA_UL_Write(IntPtr device, byte page, byte[] pdata);

        [DllImport("hfrdapi.dll")]
        static extern int TyA_UL_Authentication(IntPtr device, byte[] pKey);

        [DllImport("hfrdapi.dll")]
        static extern int TyA_UL_ChangeKey(IntPtr device, byte[] pKey);

        //======================== ISO14443A-4 Card Function 《FM1028》=======================
        [DllImport("hfrdapi.dll")]
        static extern int TyA_Reset(IntPtr device,
                                    byte mode,
                                    byte[] pData,
                                    ref byte pMsgLg);

        [DllImport("hfrdapi.dll")]
        static extern int TyA_CosCommand(IntPtr device,
                                         byte[] pCommand,
                                         byte cmdLen,
                                         byte[] pData,
                                         ref byte pMsgLg);

        [DllImport("hfrdapi.dll")]
        static extern int TyA_Deselect(IntPtr device);

        //==========================================================================
        IntPtr g_hDevice = (IntPtr)(-1); //g_hDevice must init as -1

        static char[] hexDigits = {
            '0','1','2','3','4','5','6','7',
            '8','9','A','B','C','D','E','F'};

        public static byte GetHexBitsValue(byte ch)
        {
            byte sz = 0;
            if (ch <= '9' && ch >= '0')
                sz = (byte)(ch - 0x30);
            if (ch <= 'F' && ch >= 'A')
                sz = (byte)(ch - 0x37);
            if (ch <= 'f' && ch >= 'a')
                sz = (byte)(ch - 0x57);

            return sz;
        }
        //

        #region byteHEX
        /// <summary>
        /// 单个字节转字字符.
        /// </summary>
        /// <param name="ib">字节.</param>
        /// <returns>转换好的字符.</returns>
        public static String byteHEX(Byte ib)
        {
            String _str = String.Empty;
            try
            {
                char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A',
                'B', 'C', 'D', 'E', 'F' };
                char[] ob = new char[2];
                ob[0] = Digit[(ib >> 4) & 0X0F];
                ob[1] = Digit[ib & 0X0F];
                _str = new String(ob);
            }
            catch (Exception)
            {
                new Exception("byteHEX error !");
            }
            return _str;

        }
        #endregion

        public static string ToHexString(byte[] bytes)
        {
            String hexString = String.Empty;
            for (int i = 0; i < bytes.Length; i++)
                hexString += byteHEX(bytes[i]);

            return hexString;
        }


        public static byte[] ToDigitsBytes(string theHex)
        {
            byte[] bytes = new byte[theHex.Length / 2 + (((theHex.Length % 2) > 0) ? 1 : 0)];
            for (int i = 0; i < bytes.Length; i++)
            {
                char lowbits = theHex[i * 2];
                char highbits;

                if ((i * 2 + 1) < theHex.Length)
                    highbits = theHex[i * 2 + 1];
                else
                    highbits = '0';

                int a = (int)GetHexBitsValue((byte)lowbits);
                int b = (int)GetHexBitsValue((byte)highbits);
                bytes[i] = (byte)((a << 4) + b);
            }

            return bytes;
        }


               /// <summary>
        /// ///////////gong jinhua start/////////////////////
        /// </summary>
        /// 
        public void Send_common(string TEXT)
        {
            int status;
            byte[] dataBuffer = new byte[256];
            byte cmdLen = 255;
            byte msgLen = 255;

            //Check whether the reader is connected or not
            if (true != Sys_IsOpen(g_hDevice))
            {
                MessageBox.Show("貌似没有设备连接 !", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            string oristr = TEXT;
            while (oristr.Contains(" ") | oristr.Contains("-"))
            {
                oristr = oristr.Replace(" ", "");/*去空格*/
                oristr = oristr.Replace("-", "");
            }


            richTextBox3.AppendText("->");
            richTextBox3.AppendText(oristr);//显示发送的消息
            richTextBox3.AppendText("\r\n");
            //Gets the command to send
            byte[] commandData;
            commandData = ToDigitsBytes(oristr);
            cmdLen = (byte)oristr.Length;
            cmdLen = (byte)(cmdLen / 2);
            status = TyA_CosCommand(g_hDevice, commandData, cmdLen, dataBuffer, ref msgLen);
            if (status != 0)
            {
                MessageBox.Show("指令发送失败 !", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Show response data
            String str = String.Empty;
            for (int i = 0; i < msgLen; i++)
            {
                str += byteHEX(dataBuffer[i]);
            }
            richTextBox3.AppendText("<-");
            richTextBox3.AppendText(str);//显示返回的消息
            richTextBox3.AppendText("\r\n");
            richTextBox2.Text = str;//显示返回的消息

        }


        public CPU卡调试神器FM1208()
        {
            InitializeComponent();
            checkBox1.Checked = true;
            radioButton2.Checked = true;
        }

        private void button11_Click(object sender, EventArgs e)
        {
            int status;
            string strError;

            //=========================== Connect reader =========================
            //Check whether the reader is connected or not
            if (true == Sys_IsOpen(g_hDevice))
            {
                //If the reader is already open , close it firstly
                status = Sys_Close(ref g_hDevice);
                if (0 != status)
                {
                    strError = "Sys_Close failed !";
                    MessageBox.Show(strError, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            //Connect
            status = Sys_Open(ref g_hDevice, 0, 0x0416, 0x8020);
            if (0 != status)
            {
                strError = "Sys_Open failed !";
                MessageBox.Show(strError, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            //============= Init the reader before operating the card ============
            //Close antenna of the reader
            status = Sys_SetAntenna(g_hDevice, 0);
            if (0 != status)
            {
                strError = "Sys_SetAntenna failed !";
                MessageBox.Show(strError, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Sleep(5); //Appropriate delay after Sys_SetAntenna operating 

            //Set the reader's working mode
            status = Sys_InitType(g_hDevice, (byte)'A');
            if (0 != status)
            {
                strError = "Sys_InitType failed !";
                MessageBox.Show(strError, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Sleep(5); //Appropriate delay after Sys_InitType operating

            //Open antenna of the reader
            status = Sys_SetAntenna(g_hDevice, 1);
            if (0 != status)
            {
                strError = "Sys_SetAntenna failed !";
                MessageBox.Show(strError, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Sleep(5); //Appropriate delay after Sys_SetAntenna operating


            //============================ Success Tips ==========================
            //Beep 200 ms
            status = Sys_SetBuzzer(g_hDevice, 20);
            if (0 != status)
            {
                strError = "Sys_SetBuzzer failed !";
                MessageBox.Show(strError, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //else  每次都提示复位成功 算了 叫一下 也即是成功了
            //{
              //  MessageBox.Show("复位成功");
            //}
        }

        private void button12_Click(object sender, EventArgs e)
        {
            int status;
            string strError;
            byte mode = 0x52; //WUPA mode, request cards of all status
            byte[] dataBuffer = new byte[256];
            byte len = 255;

            //Check whether the reader is connected or not
            if (true != Sys_IsOpen(g_hDevice))
            {
                MessageBox.Show("Not connect to device !", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            richTextBox3.Text = "CSN也就是UID:";
 

            //Close and then open the antenna in order to achieve multiple reset card.
            //(If you need to reset the card several times, you need to increase the turn off, open the antenna function.)
            //Close antenna of the reader
            status = Sys_SetAntenna(g_hDevice, 0);
            if (0 != status)
            {
                strError = "Sys_SetAntenna failed !";
                MessageBox.Show(strError, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Sleep(5); //Appropriate delay after Sys_SetAntenna operating 

            //Open antenna of the reader
            status = Sys_SetAntenna(g_hDevice, 1);
            if (0 != status)
            {
                strError = "Sys_SetAntenna failed !";
                MessageBox.Show(strError, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Sleep(5); //Appropriate delay after Sys_SetAntenna operating

            //Reset card
            status = TyA_Reset(g_hDevice, mode, dataBuffer, ref len);
            if (status != 0)
            {
                MessageBox.Show("TyA_Reset failed !", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Show  CSN and  Reset  information
            String str = String.Empty;
            for (int i = 0; i < 4; i++)
            {
                str += byteHEX(dataBuffer[i]);
            }
            richTextBox3.AppendText(str);
            richTextBox3.AppendText("\r\n");

            str = String.Empty;
            for (int i = 0; i < len - 4; i++)
            {
                str += byteHEX(dataBuffer[i + 4]);
            }
            richTextBox3.AppendText("复位信息:");
            richTextBox3.AppendText(str);
            richTextBox3.AppendText("\r\n");
        }

        private void button13_Click(object sender, EventArgs e)
        {
            richTextBox3.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
             Send_common(textBox1.Text.Trim());//优化 支持分隔符
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Send_common(textBox2.Text.Trim());
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Send_common(textBox3.Text.Trim());
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Send_common(textBox4.Text.Trim());
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Send_common(textBox5.Text.Trim());
        }

        private void button6_Click(object sender, EventArgs e)
        {
            Send_common(textBox6.Text.Trim());
        }

        private void button7_Click(object sender, EventArgs e)
        {
            Send_common(textBox7.Text.Trim());
        }

        private void button8_Click(object sender, EventArgs e)
        {
            Send_common(textBox8.Text.Trim());
        }

        private void button9_Click(object sender, EventArgs e)
        {
            Send_common(textBox9.Text.Trim());
        }

        private void button10_Click(object sender, EventArgs e)
        {
            Send_common(textBox10.Text.Trim());
        }

        private void button14_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)//DES勾选
            {
                if (checkBox1.Checked == false)//正常模式
                {
                    byte[] pwdData;
                    pwdData = ToDigitsBytes(textBox21.Text.Trim());
                  //  SetKey(pwdData);

                    byte[] inDate = new byte[8];
                    inDate = ToDigitsBytes(richTextBox2.Text.Trim());

                    byte[] outDate = new byte[8];

                    unsafe
                    {
                        DO_DES(inDate,pwdData, outDate);
                    }

                    richTextBox1.Text = ToHexString(outDate);
                }
                else
                {
                    byte[] pwdData;
                    pwdData = ToDigitsBytes(textBox21.Text.Trim());
                   // SetKey(pwdData);

                    byte[] inDate;// = new byte[8];
                    if (richTextBox2.Text.Length < 8)
                    {
                        MessageBox.Show("至少需要8位", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    inDate = ToDigitsBytes(richTextBox2.Text.Trim().Substring(0, 8));//C53DEA759000 也就是8个有效+9000

                    byte[] outDate = new byte[8];
                    unsafe
                    {
                        // PlayDes(outDate, inDate);
                        DO_DES(inDate, pwdData, outDate);
                    }
                    richTextBox1.Text = "0082000008" + "-" + ToHexString(outDate);

                }
            }
            else if (radioButton2.Checked == true)//3DES模式
            {

                if (checkBox1.Checked == false)//正常模式
                {
                    byte[] pwdData;
                    pwdData = ToDigitsBytes(textBox21.Text.Trim());
  
                    byte[] inDate = new byte[8];
                    inDate = ToDigitsBytes(richTextBox2.Text.Trim());

                    byte[] outDate = new byte[8];

                    unsafe
                    {
                        DO_3DES(inDate, pwdData, outDate);
                    }

                    richTextBox1.Text = ToHexString(outDate);
                }
                else if (checkBox1.Checked == true)//傻瓜模式
                {
                    byte[] pwdData;
                    pwdData = ToDigitsBytes(textBox21.Text.Trim());

                    byte[] inDate;// = new byte[8];
                    if (richTextBox2.Text.Length < 8)
                    {
                        MessageBox.Show("至少需要8位", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    inDate = ToDigitsBytes(richTextBox2.Text.Trim().Substring(0, 8));//C53DEA759000 也就是8个有效+9000

                    byte[] outDate = new byte[8];
                    unsafe
                    {
                        DO_3DES(inDate, pwdData, outDate);
                    }
                    richTextBox1.Text = "0082000008" + "-" + ToHexString(outDate);


                }
            }

        }

        private void button15_Click(object sender, EventArgs e)
        {
            // System.IO.File.WriteAllText(@"C:\Users\Gong Jin Hua\Desktop\TEM\ggg.txt", richTextBox2.Text);
            /*1杰杰的代码：直接在指定路径下建立文件 写入内容 如果以前有 就直接覆盖*/

            /*2https://wenda.so.com/q/1486411527494579?src=180*/
            // 利用SaveFileDialog，让用户指定文件的路径名
            SaveFileDialog saveDlg = new SaveFileDialog();
            saveDlg.Filter = "文本文件|*.txt";
            if (saveDlg.ShowDialog() == DialogResult.OK)
            {
                // 创建文件，将textBox1中的内容保存到文件中
                // saveDlg.FileName 是用户指定的文件路径
                FileStream fs = File.Open(saveDlg.FileName,/*最前面using System.IO;*/
                FileMode.Create,
                FileAccess.Write);
                StreamWriter sw = new StreamWriter(fs);

                // 保存textBox1中所有内容（所有行）
                foreach (string line in richTextBox3.Lines)
                {
                    sw.WriteLine(line);
                }
                //关闭文件
                sw.Flush();
                sw.Close();
                fs.Close();
                // 提示用户：文件保存的位置和文件名
                MessageBox.Show("文件已成功保存到" + saveDlg.FileName);
            }
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked == true)
                this.TopMost = true;
            else
                this.TopMost = false;
        }

        private void button16_Click(object sender, EventArgs e)
        {
            Send_common(richTextBox1.Text.Trim());
        }

        private void CPU卡调试神器FM1208_Load(object sender, EventArgs e)
        {//MOVE
            this.Resize += new EventHandler(MainForm_Resize); //添加窗体拉伸重绘事件
            xvalues = this.Width;//记录窗体初始大小
            yvalues = this.Height;
            SetTag(this);
        }
        private void MainForm_Resize(object sender, EventArgs e)//重绘事件
        {//MOVE
            float newX = this.Width / xvalues;//获得比例
            float newY = this.Height / yvalues;
            SetControls(newX, newY, this);
        }
        private void SetControls(float newX, float newY, Control cons)//改变控件的大小
        {//MOVE
            foreach (Control con in cons.Controls)
            {
                string[] mytag = con.Tag.ToString().Split(new char[] { ':' });
                float a = Convert.ToSingle(mytag[0]) * newX;
                con.Width = (int)a;
                a = Convert.ToSingle(mytag[1]) * newY;
                con.Height = (int)a;
                a = Convert.ToSingle(mytag[2]) * newX;
                con.Left = (int)a;
                a = Convert.ToSingle(mytag[3]) * newY;
                con.Top = (int)a;
                Single currentSize = Convert.ToSingle(mytag[4]) * newY;

                con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
                if (con.Controls.Count > 0)
                {
                    SetControls(newX, newY, con);
                }
            }
        }
        /// <summary>
        /// 遍历窗体中控件函数
        /// </summary>
        /// <param name="cons"></param>
        private void SetTag(Control cons)
        {//MOVE
            foreach (Control con in cons.Controls)  //遍历窗体中的控件,记录控件初始大小
            {
                con.Tag = con.Width + ":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
                if (con.Controls.Count > 0)
                {
                    SetTag(con);
                }
            }
        }

        private void textBox28_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox27_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox20_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox19_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox18_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox17_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox16_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox15_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox14_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox29_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox13_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox12_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox11_TextChanged(object sender, EventArgs e)
        {

        }

        private void button21_Click(object sender, EventArgs e)
        {
            Send_common(textBox22.Text.Trim());
        }

        private void button20_Click(object sender, EventArgs e)
        {
            Send_common(textBox23.Text.Trim());
        }

        private void button19_Click(object sender, EventArgs e)
        {
            Send_common(textBox24.Text.Trim());
        }

        private void button18_Click(object sender, EventArgs e)
        {
            Send_common(textBox25.Text.Trim());
        }

        private void button17_Click(object sender, EventArgs e)
        {
            Send_common(textBox26.Text.Trim());
        }

        private void button22_Click(object sender, EventArgs e)
        {
            MessageBox.Show("技术支持GKoSon");
        }

        private void button23_Click(object sender, EventArgs e)
        {/*https://blog.csdn.net/yysyangyangyangshan/article/details/7268832*/
         /*https://blog.csdn.net/TimeBYTime/article/details/49616689*/

            if (button23_Click_flag == 1)
            {
                button23_Click_flag = 2;
#if false
                string note = @"6700-错误的长度                       
                            6A80-数据或者参数错误
                            6982-不满足安全状态
                            6984-文件无足够空间
                            6986-参数P1P2错误
                            6A88-秘钥未找到
                            6A82-KEY文件为找到
                            63C7-认证失败还有7次";
                richTextBox1.Text = note;
#endif
                string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                path += "Info.md";
                string note  = File.ReadAllText(path);
                richTextBox1.Text = note;
            }
            else if(button23_Click_flag == 2)
            {
                button23_Click_flag = 1;
                richTextBox1.Text = "";
            }
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            textBox21.Text = "FFFFFFFFFFFFFFFF";
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            textBox21.Text = "112233445566778899AABBCCDDEEFF00";
        }

        private void button24_Click(object sender, EventArgs e)
        {
            string strError;
            if (richTextBox1.Text.Trim().Length<20)//此时不允许保存
            {
                strError = "数据小于20此时不能保存!";
                MessageBox.Show(strError, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            path += "Info.md";
            System.IO.File.WriteAllText(path, richTextBox1.Text);
            //(@"C:\Users\Gong Jin Hua\Desktop\TEM\ggg.txt", richTextBox1.Text);
        }
        /*
         * uint8_t selectDir[] ={0x02,0x00,0xA4,0x00,0x00,0x02,0x3F,0x00};//读通卡卡号
	uint8_t readCard[]={0x03,0x00,0xB0,0x85,0x0C,0x08};//读通卡卡号 返回 0x80 0x10 0x3 0x40 0x0 0x0 0x2 0x12 0x0 0x39 0x63 0x90 0x0 0xEB 0xCC 0x8 0x0 0x0 
	
	uint8_t uSelectProperty[]={0x02,0x00,0xA4,0x00,0x00,0x02,0xDC,0x06};//选择地产物业应用目录
	uint8_t uSelectReadBinFile[]={0x03,0x00,0xA4,0x00,0x00,0x02,0x00,0x15};//读取其他二进制文件（0015）前48字节 0x30
	uint8_t uSelectReadBinContent[]={0x02,0x00,0xB0,0x00,0x00,0x30};//读取文件内容
	uint8_t uSelectReadBinFile1[]={0x03,0x00,0xA4,0x00,0x00,0x02,0x00,0x15};//读取其他二进制文件（0015）从0x30 后的 48字节
	uint8_t uSelectReadBinContent1[]={0x02,0x00,0xB0,0x00,0x30,0x35};//读取文件内容
	不知道陈强为什么再前面2 3跳着
         */
        private void button25_Click(object sender, EventArgs e)
        {
            String string_dir1 = "00A40000023F00";
            String string_read = "00B0850C08";
            String string_dir2 = "00A4000002DC06";
            String string_file = "00A40000020015";
            String string_read1 = "00B0000030";
            String string_read2 = "00B0003035";
            Send_common(string_dir1);
            Send_common(string_read);
            Send_common(string_dir2);
            Send_common(string_file);
            Send_common(string_read1);
            Send_common(string_file);
            Send_common(string_read2);
        }
    }
}
